// 注意: 需要启用线程支持
// 编译命令: asc threads.ts -o threads.wasm --enable threads

let sharedBuffer: i32;
let sharedView: Int32Array = new Int32Array(0);

// 初始化共享内存
export function initSharedMemory(ptr: i32, size: i32): void {
  sharedBuffer = changetype<i32>(ptr);
  sharedView = new Int32Array(sharedBuffer);
}

// 工作线程函数
export function workerCompute(start: i32, end: i32): i32 {
  let sum = 0;
  for (let i = start; i <= end; i++) {
    sum += i;
  }
  return sum;
}
